﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zove.Runtime;
using EmbeddedSharp.Core;
using WeifenLuo.WinFormsUI.Docking;

namespace Zove.Desktop.Tools {
    public partial class FunctionManager : DockContent {

        private Dictionary<string, int> funcIndex = new Dictionary<string, int>();
        
        public FunctionManager() {
            InitializeComponent();

            this.Load += new EventHandler(FunctionManager_Load);
        }

        public void FunctionManager_Load(object sender, EventArgs e) {
            this.tbFilter.AutoCompleteCustomSource = new AutoCompleteStringCollection();
                        
            foreach(string key
                in ZoveDependencyManager.Instance.FunctionManager.Functions.Keys) {
                this.tbFilter.AutoCompleteCustomSource.Add(key);
                FuncNode fn = ZoveDependencyManager.Instance.FunctionManager.GetFunction(key);
                int idx = this.gvFunctions.Rows.Add(new string[] {
                    fn.Value, fn.GetType().Namespace });
                funcIndex.Add(fn.Value, idx);
            }
        }

        private void tbFind_Click(object sender, EventArgs e) {
            if (!funcIndex.ContainsKey(this.tbFilter.Text)) {
                return;
            }

            int idx = funcIndex[this.tbFilter.Text];
            this.gvFunctions.Rows[idx].Selected = true;
        }
    }
}
